package com.netease.nimlib.ipc.cp.client;

import android.content.Context;
import android.net.Uri;
import android.text.TextUtils;
import android.util.Log;

import com.netease.nimlib.ipc.cp.protocol.Protocol;

/**
 * 数据变更通知，一般在remote端(数据源提供端)调用
 * <p>
 * Created by huangjun on 2017/11/15.
 */

public class Notifier {

    private Notifier() {
    }

    public static void notifyChange(final Context context, final String name, final String key, final ProviderClient.UriTypeEnum type) {
        if (context == null || TextUtils.isEmpty(name) || TextUtils.isEmpty(key)) {
            return;
        }

        Uri uri = Protocol.buildUri(name, key, type.getInt());
        Log.i(Protocol.TAG, "notify change, uri=" + uri);
        context.getContentResolver().notifyChange(uri, null);
    }

    public static void notifyChange(final Context context, final Uri uri) {
        if (context == null || uri == null) {
            return;
        }

        Log.i(Protocol.TAG, "notify change, uri=" + uri);
        context.getContentResolver().notifyChange(uri, null);
    }
}
